﻿<%@ WebHandler Language="C#" Class="PublishDetailInfo" %>

using System;
using System.Web;
using Chenxin.Lib.Utility;
using System.Data;
using System.Text;
using System.Data.SqlClient;

public class PublishDetailInfo : AjaxHandlerBase
{

    public PublishDetailInfo()
    {
        //编辑信息
        //htTypePermit.Add("editpublic", Constants.Permit_EditPublicInfo);
        //删除信息
        htTypePermit.Add("delpublic", Constants.Permit_DelPublicInfo);
        //管理信息
        htTypePermit.Add("mgrpublic", Constants.Permit_MgrPublicInfo);
    }
    
    override public void RequestProcess(HttpContext context)
    {
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";

        if (!string.IsNullOrEmpty(context.Request.Params["op"]))
        {
            //处理类型
            string strOperate = context.Request.Params["op"];
            string strResponse = "";
            switch (strOperate.Trim())
            {
                case "getmodel":
                    strResponse = GetModel(context);
                    break;
                case "delpublic":
                    DelPublicInfo(context);
                    break;
                case "mgrpublic":
                    DelPublicInfo(context);
                    break;
                default:
                    break;
            }
            context.Response.Write(strResponse);
        }
    }

    /// <summary>
    /// 获取实体
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private string GetModel(HttpContext context)
    {
        try
        {
            string strRecordId = string.Empty;
            strRecordId = context.Request.Params["modelid"].ToString().Trim();
            Chenxin.Lib.Hr.Entity.Pblish_Info pblish_info = Chenxin.Lib.Hr.BLL.Pblish_Info.GetModel(new Guid(strRecordId));
            Chenxin.Lib.Hr.Entity.Pblish_Info model = new Chenxin.Lib.Hr.Entity.Pblish_Info();
            model.PublisherId = pblish_info.PublisherId;
            model.DepartId = CurrentUserInfo.UserId;
            return retExecResult(Constants.ExecResult.Succ, "", model);
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }

    public void DelPublicInfo(HttpContext context)
    {
        try
        {
            if (string.IsNullOrEmpty(context.Request["recordid"]))
                context.Response.Write(retExecResult(Constants.ExecResult.Error, "标识不存在，请重试！", ""));

            Chenxin.Lib.Hr.Entity.Pblish_Info model = Chenxin.Lib.Hr.BLL.Pblish_Info.GetModel(new Guid(context.Request["recordid"]));

            model.IsDel = true;
            //删除信息(逻辑删除)
            Chenxin.Lib.Hr.BLL.Pblish_Info.Update(model);
            //删除其附件信息(物理删除)
            Chenxin.Lib.Hr.BLL.Attachment.DeleteByReportId(model.RecordId);

            //context.Response.Write(retExecResult(Constants.ExecResult.Succ, "删除成功！", "{InfoType:'" + model.InfoType + "'}"));
            context.Response.Write(string.Format("{{success:1,msg:'删除成功！',data:{{InfoType:'{0}'}}}}", model.InfoType));

        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }

}